var httpsUrl = getApp().globalData.httpsUrl;
var globalData = getApp().globalData;
var commonUtil = require("../../../utils/commonUtil.js")
Page({
  data: {
    imgUrl: globalData.imgUrl,
    todayIncome:'0.00',
    balance:'0.00',
    businessCode:'',
  },
  loadData:function(){
    let that = this;
    commonUtil.showLoading("请稍等...");
    let openId = wx.getStorageSync("openidKey");
    let sid = wx.getStorageSync("JSESSIONID");
    console.log("header:openId:" + openId + ",sid:" + sid);
    wx.request({
      header: { "openId": openId, "sid": sid },
      url: httpsUrl + "/businessManage/businessInfo",
      dataType: "json",
      method: "POST",
      // data: params,
      success: function (res) {
        commonUtil.hideLoading();
        var res = res.data;
        console.log(JSON.stringify(res));
        if (res.result == 0) {
          that.setData({ todayIncome: res.data.todayIncome, businessCode: res.data.businessCode, balance: res.data.balance})
        }
      }
    })
  },
  //扫码
  scanCode: function (e) {
    let id = e.currentTarget.id;
    wx.removeStorageSync("code");
    let that = this;
    wx.scanCode({
      success: (res) => {
        // 扫码结果:{"errMsg":"scanCode:ok","result":"d1d506a0739940c5a33877b86516cde8","scanType":"QR_CODE","charSet":"UTF-8"}
        console.log("扫码结果:" + JSON.stringify(res));
        let result = res.result;
        if (commonUtil.isEmpty(result) || result =="www.liantu.com") {
          wx.showToast({title: '未获取到核销码，请重试',icon: 'success',duration: 2000})
        }else{
          wx.setStorageSync("code", result);
          if(id==1){
            wx.navigateTo({url: '../voucherHX/voucherHX',})
          } else if (id == 2) {
            wx.navigateTo({ url: '../orderHX/orderHX', })
          }
        }
      },
      fail: (res) => {
        wx.showToast({title: '扫码失败',icon: 'success',duration: 2000})
      },
    })
  },
  
  voucherHX:function(){
    wx.navigateTo({url: '../voucherHX/voucherHX',})
  },
  orderHX:function(){
    wx.navigateTo({url: '../orderHX/orderHX',})
  },
  shopVoucherList:function(){
    wx.navigateTo({url: '../shopVoucherList/shopVoucherList',})
  },
  shopCardList:function(){
    wx.navigateTo({url: '../shopCardList/shopCardList',})
  },
  shopPoster:function(){
    wx.navigateTo({url: '../shopPoster/shopPoster',})
  },
  orderHXList:function(){
    wx.navigateTo({url: '../../order/orderHXList/orderHXList',})
  },
  smsk:function(){
    wx.showToast({title: '待开放~',})
  },
  shopCode:function(){
    let businessCode = this.data.businessCode;
    if (businessCode.length>0){
      wx.navigateTo({
        url: '../shopCode/shopCode?businessCode=' + businessCode,
      })
    }else{
      wx.showModal({title: '提示',content: '未获取到商家码，请稍后重试',})
    }
  },
  putforward:function(){
    wx.showModal({title: '提示',content: '请前往管理平台提现哦',})
    // wx.navigateTo({
    //   url: '../putforward/putforward',
    // })
  },
  onLoad: function (options) {
    this.loadData();
  },
  onShow: function () {
    this.loadData();
  },
})